package com.freesun.monitor.ld;

import com.freesun.monitor.fs.FastDfs;
import com.freesun.monitor.fs.OfastDfs;
//import lrapi.lr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by yangfei on 13-12-11.
 */
public class OfastDfsDownMonitor {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    private FastDfs fastDfs;
    private OfastDfs ofastDfs;
    private String clientPath = "E:\\fastdfs\\fdfs_client.conf";
    private String localFilePath = "E:\\fastdfs\\fastdfs06.jpg";
    private String group_name = "group1";
    private String remoteFileName = "M00/00/00/wKgBdlKoGxOAKRE3AAFXEJFjj14787.jpg";
    private String localeFileName = "E:\\fastdfs\\down\\" + remoteFileName.substring(remoteFileName.lastIndexOf("/") + 1, remoteFileName.length());
    private String type = "jpg";
    //定义线程组活动线程数
    private int ac;


    /**
     * @return
     * @throws Throwable
     * @desc 初始化连接数据库
     */
    public int init() throws Throwable {
        fastDfs = new FastDfs();
        ofastDfs = new OfastDfs();
        return 0;
    }

    /**
     * @return
     * @throws Throwable
     * @desc 可以执行多次，可以进行参数操作
     */
    public int action() throws Throwable {

        //lr.message("开始下载文件:" + localFilePath);
        ac = ofastDfs.multDown(clientPath,group_name,remoteFileName,localeFileName,type, fastDfs);
        //lr.message("下载文件:"+localFilePath+"成功!");
        return 0;
    }

    /**
     * @return
     * @throws Throwable
     * @desc 销毁数据只执行一次
     */
    public int end() throws Throwable {
        if (ac == 0) {
            log.debug("没有活动线程");
        } else {
            log.debug("有活动线程");
        }
        return 0;
    }
}
